// src/stores/loading.ts
import { defineStore } from 'pinia';

export const useLoadingStore = defineStore('loading', {
    state: () => ({
        loadingCount: 0, // 当前正在进行的请求数量
        isLoading: false // 是否显示加载状态
    }),
    actions: {
        // 开始加载
        startLoading() {
            this.loadingCount++;
            this.isLoading = true;
        },
        // 结束加载
        endLoading() {
            this.loadingCount--;
            if (this.loadingCount <= 0) {
                this.loadingCount = 0;
                this.isLoading = false;
            }
        },
        // 重置加载状态
        resetLoading() {
            this.loadingCount = 0;
            this.isLoading = false;
        }
    }
});